<script setup lang="ts">
const topBarProxy = async (e: MouseEvent) => {
  const instance = e.target as HTMLElement
  const {index} = instance.dataset;

  const currentID = await window.ipcRenderer.invoke('get-focus')
  if (currentID) {
    switch (index) {
      case '0':
        // 将窗口最小化
        window.ipcRenderer.send(`set-mini-window-${currentID}`)
        break
      case '1':
        // 将窗口最大化
        window.ipcRenderer.send(`set-max-window-${currentID}`)
        break
      case '2':
        // 关闭整个程序
        window.ipcRenderer.send(`set-close-window-${currentID}`)
        break
      default:
        break
    }
  }
}
</script>

<template>
  <div class="slid-top" @click="topBarProxy">
    <div class="icon-box no_drag">
      <el-icon>
        <i-ep-minus/>
      </el-icon>
      <div class="mark_icon" data-index="0"></div>
    </div>
    <div class="icon-box no_drag">
      <el-icon>
        <i-ep-fullScreen/>
      </el-icon>
      <div class="mark_icon" data-index="1"></div>
    </div>
    <div class="icon-box close no_drag">
      <el-icon>
        <i-ep-close/>
      </el-icon>
      <div class="mark_icon" data-index="2"></div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.slid-top {
  width: 100%;
  height: 25px;
  background-color: rgb(27, 27, 27);
  display: flex;
  justify-content: end;
  align-items: center;

  .icon-box {
    width: 30px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    //:nth-of-type()
    position: relative;

    &:hover {
      background-color: rgb(36, 36, 36);

      &.close {
        background-color: rgb(196, 43, 28);
      }
    }

    .clear {
      background-color: transparent !important;
    }

    .mark_icon {
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: transparent;
    }
  }
}
</style>